import {execByCode} from "@/request/flow";

export function doFromInfoValue(properties:any, formBuildList:any, execFunc:any) {
    // 获取下拉选项值
    if (properties.valueType === 'CUSTOM') {
        // 从自定义的值中获取下拉选项值
        let custom = properties.customValue;
        // 将字符串解析为数组
        try {
            let customList = JSON.parse(custom);
            execFunc(customList)
        } catch (Error) {
            execFunc(custom)
        }
    } else if (properties.valueType === 'FORM_INTERFACE') {
        let realFormConditionList = properties.realFormConditionList;
        let formInterfaceCodeList = properties.formInterfaceCode;
        // 构建参数
        let param = {
            code: formInterfaceCodeList[2],
            execParam: []
        }
        for (let i = 0; i < realFormConditionList.length; i++) {
            let item = realFormConditionList[i];
            let execParamItem = {
                id: item.code,
                labelName: item.labelName,
                value: ""
            }
            if (item.selectType === 'custom') {
                execParamItem.value = item.customContent;
            } else if (item.selectType === 'formParam') {
                // 获取表单参数
                for (let index = 0; index < formBuildList.length; index++) {
                    if (item.formParam === formBuildList[index].code) {
                        execParamItem.value = formBuildList[index].bindValue ? formBuildList[index].bindValue : "";
                        break;
                    }
                }
            }
            param.execParam.push(execParamItem);
        }
        // 调用表单外部接口查询
        execByCode(param).then((res) => {
            execFunc(res.data)
        })
    }
}